<template>
  <div class="about">
    <button @click="sendMessage">发消息</button>
  </div>
</template>

<script>
import { onMounted } from '@vue/runtime-core'
import { connection } from '../utils/signalR/index'
export default {
  setup () {
    onMounted(() => {
      connectServer()
    })
    const connectServer = () => {
      connection.on('ReceiveMessage', message => {
        console.log(message)
        // this.getMessage(message)
        // this.getEventList()
      })
      connection.start()
    }
    const sendMessage = () => {
      connection.invoke('SendMessage', `测试消息--${+new Date()}`).catch(err => console.error(err))
    }
    return {
      sendMessage
    }
  }
}
</script>
